<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/vue@3.2.26/dist/vue.global.js"></script>
<style>
    .show{display: inherit}
    .hide{display: none}
    .layui-btn{margin-right: 10px}
.lay-pic {
    max-height: 40px;
}
.layui-table-cell {overflow-x: hidden;overflow: inherit; }
.layui-table-cell{padding:2px 4px;line-height:20px;}
th span,.layui-table-cell{white-space:normal;}
.layui-form-item .layui-inline{margin-right:0px;}
.createBillTemp{line-height:38px;}
.createBillTemp select{width:180px;height:30px;}
.fixed-bar{height:auto !important;}
.redclass{color:red;font-weight:bold;}

    .small-table{margin: 0; }
    .small-table td{padding: 4px;font-size: 10px}
    .unit_count{text-decoration:underline;padding:0px 8px;cursor: pointer;
        color:#3399FF}
    .layui-form-pane .layui-form-label{width:auto;}
    .layui-form-item{margin-bottom:0px;}
	.have_loss{color:red;}
</style>

<div class="fixed-bar">
    <form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search" >
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="client_ordernum" value="" lay-verify="" placeholder="输入订单号" class="layui-input">
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">SKU</label>
                <div class="layui-input-inline">
                    <input type="text" name="sku" value="" lay-verify="" placeholder="输入SKU" class="layui-input">
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">盈亏情况</label>
                <div class="layui-input-inline">
                    {:Form::select('profit_id', '', $ProfitOrLoss, '', '')}
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">下单日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="create_date_range" readonly="" id="create_date_range" lay-verify="" placeholder="选择下单日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">更新时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="update_date_range" readonly="" id="update_date_range" lay-verify="" placeholder="选择更新日期" class="layui-input">
                </div>
            </div>
            <div class="layui-inline removeStat">
                <label class="layui-form-label">所属工厂</label>
                <div class="layui-input-inline">
                    {:Form::select('factory_id', '', $factoryKV, '', '')}
                </div>
            </div>
            <div class=" layui-inline layui-upload">
                <button type="submit" class="layui-btn"  lay-submit="" lay-filter="demo1"  >搜索</button>
            </div>
        </div>
    </form>
</div>

<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}

<div id="prcessTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
      <table width="100%" border="0">
          <tr>
            <td>原加工费</td>
            <td>核价差异</td>
            <td>订单件数</td>
            <td>mes入仓数</td>
            <td>裁剪数量</td>
            <td>核价总金额</td>
            <td>工厂总单价</td>
            <td>单价占比</td>
            <td>盈亏情况</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td>12</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
      </table>

	</div>
	</form>
</div>

<div id="fabricTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
        <table width="100%" border="0">
          <tr>
            <td>物料名称</td>
            <td>客户开单价</td>
            <td>开单总米数</td>
            <td>实际总米数</td>
            <td>余料</td>
            <td>实际总金额</td>
            <td>开单总金额</td>
            <td>赢亏情况</td>
          </tr>
          {{#  for(var i=0;i<d.omlist.lenth;i++){ }}
          <tr>
            <td>{{layui.tool.formatMaterialType(d.omlist[i].material_type,'',2)}}<span class='copy-item'>{{d.omlist[i].material_name}}</span></td>
            <td></td>
            <td>12</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          {{#  } }}
        </table>

	</div>
	</form>
</div>
<div id="coverLossTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
        <table width="100%" border="0">
          <tr>
            <td>总匹数</td>
            <td>开单单价</td>
            <td>开单总金额</td>
            <td>实际总米数</td>
            <td>实际总金额</td>
            <td>实际补损金额</td>
            <td>补损后总金额</td>
            <td>补损后总米数</td>
            <td>补损米数</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td>12</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>

	</div>
	</form>
</div>
<div id="checkinoutTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
        <table width="100%" border="0">
          <tr>
            <td>MES入仓数</td>
            <td>入库数</td>
            <td>出其它单库存数</td>
            <!--<td>出库数</td>-->
            <td>裁数</td>
            <td>补裁片</td>
            <td>正品率</td>
            <td>fob价</td>
            <td>正品差数</td>
            <td>盈亏情况</td>
          </tr>
          <tr>
            <td>{{d.store_count}}</td>
            <td>{{d.available_checkin_count}}</td>
            <td>{{d.available_checkout_count}}</td>
            <!--<td>12</td>-->
            <td>{{d.shicai_count}}</td>
            <td>{{d.sew_cut_count}}</td>
            <td>{{d.available_pre}}</td>
            <td>{{d.price}}</td>
            <td>{{d.cut_diff}}</td>
            <td>{{d.cut_diff_money}}</td>
          </tr>
        </table>

	</div>
	</form>
</div>
<div id="useMaterialTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
        <table width="100%" border="0">
          <tr>
            <td>面料</td>
            <td>原用量</td>
            <td>实际用量</td>
            <td>差率</td>
            <td>用量复核</td>
            <td>裁剪数量</td>
            <td>MES入仓数</td>
            <td>复核总金额</td>
            <td>盈亏情况</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td>12</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>

	</div>
	</form>
</div>
<div id="secondProcessTpl" class="hide">
<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
	<div class="layui-form-item pt20 pl20">
        <table width="100%" border="0">
          <tr>
            <td>二次工艺名称</td>
            <td>原单价</td>
            <td>实际用量</td>
            <td>差率</td>
            <td>用量复核</td>
            <td>裁剪数量</td>
            <td>MES入仓数</td>
            <td>复核总金额</td>
            <td>盈亏情况</td>
          </tr>
          <tr>
            <td></td>
            <td></td>
            <td>12</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>

	</div>
	</form>
</div>

<script type="text/html" id="skuTpl">
    <span class="copy-item">{{ d.client_ordernum }}</span>  <span title="{{ layui.util.toDateString(d.create_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.create_time * 1000,'MM-dd') }} </span><br>
    <span class="copy-item">{{ d.sku }}</span></br>
</script>
<script type="text/html" id="factoryTpl">	
	{{factoryKV[d.factory_id]}}<br />
    {{d.os_order_count}}件 
	{{# if(d.client_status == 99){ }}
		<span class="red">{{ clientStatus[d.client_status] }}</span>
	{{# }else{ }}
		{{ clientStatus[d.client_status] }}
	{{# } }}
</script>

<script type="text/html" id="createTimeTpl">
{{# if(d.create_time > 0){ }} 
	<span title="{{ layui.util.toDateString(d.create_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.create_time * 1000,'MM-dd') }} </span>
{{# } }}
</script>
<script type="text/html" id="caichuangTimeTpl">
{{# if(d.create_time > 0){ }} 
	<span title="{{ layui.util.toDateString(d.caichuang_over_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.caichuang_over_time * 1000,'MM-dd') }} </span>
{{# } }}
</script>
<script type="text/html" id="processColnumTpl">
	<a data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="加工费盈亏" data-tpl="prcessTpl" class="process_btn"> 120<br> 无亏损 </a>
</script>
<script type="text/html" id="fabricColnumTpl">
	<a data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{d.omlistJson}}' title="面辅料盈亏" data-tpl="fabricTpl" class="process_btn"> 120<br> 无亏损 </a>
</script>
<script type="text/html" id="coverLossColnumTpl">
	<a data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="补损详情" data-tpl="coverLossTpl" class="process_btn"> 120<br> 无亏损 </a>
</script>
<script type="text/html" id="checkinoutColnumTpl">
	<a data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="正品盈亏" data-tpl="checkinoutTpl" class="process_btn"> {{d.cut_diff_money}}<br> 
	{{# if(d.cut_diff_money < 0){ }}<span class="have_loss">亏损</span> {{# }else{ }} 无亏损 {{# } }}
	</a>
</script>
<script type="text/html" id="useMaterialColnumTpl">
	<a data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="用量盈亏" data-tpl="useMaterialTpl" class="process_btn"> 120<br> 无亏损 </a>
</script>
<script type="text/html" id="secondProcessColnumTpl">
	<a data-id="{{ d.id }}" data-ordernum='{{ d.client_ordernum}}' data-json='{{ d.osJson }}' title="二次工艺核价" data-tpl="secondProcessTpl" class="process_btn"> 120<br> 无亏损 </a>
</script>


<script type="text/html" id="toolbar">
    <span>盈亏占比：无盈亏85%（1250单） ； 亏损25% （360单/889.50元）</span>
    &nbsp;&nbsp;&nbsp;
    <a href="{:url('addConfig')}" class="layui-btn layui-btn-warm layui-btn-sm  hisi-iframe" hisi-data="{width: '50%', height: '50%'}" style="float:right;"  title="设置">&nbsp;设置</a>
</script>
<script type="text/html" id="clientStatusTpl">
    {{# if(d.status == 99){ }}<span class="layui-badge">{{ d.delete_text }}</span><br> {{# } }}
	{{ clientStatus[d.client_status].replace(/生产中/, "") }}
</script>


<script type="text/javascript">
	var factoryKV = {:json_encode($factoryKV);};
	var clientStatus = {:json_encode($clientStatus);};
	
	layui.use([ 'opTable', 'jquery', 'tool', 'laydate', 'laytpl', 'form'], function() {
		var $ = layui.jquery;
		var laytpl = layui.laytpl;
		var form = layui.form;
		var laydate = layui.laydate;
		
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#update_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#update_date_range').val(value);
            	$('#layui-laydate2').remove();//关闭面板
            }
		});

		var opTable = layui.opTable.render({
			elem : '#dataTable'
			,url : '{:url()}'
			,page: true
			,even: true
			,limit: 20
            ,limits: [5,10,20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
			,openVisible: false
            ,toolbar: '#toolbar'
	        ,defaultToolbar: ['filter', 'exports', 'print']
			,cols : [[ 
				{field: 'col1', title: '订单号/下单日期/sku', templet:'#skuTpl',width:160}
			    ,{field: 'factory', title: '分配工厂/件数/进度', templet:'#factoryTpl',width:130}
				,{field: 'shicai_count', title:'图片',templet:function(d){return '<span class="lay-pic-container" src="'+ d.pic +'"><img src="'+ d.pic +'" class="lay-pic"></span>'}}
				,{field: 'sew_cut_count', title:'订单总盈亏',templet:function(d){ return '无亏损'; }}
				,{field: 'jiaohuo_count', title:'加工费/盈亏',templet:"#processColnumTpl"}
				,{field: 'field0', title:'面辅料/盈亏',templet:"#fabricColnumTpl"}
				,{field: 'cost', title:'用量/盈亏',templet:"#useMaterialColnumTpl"}
				,{field: 'defective_checkin_count', title:'二次工艺(染色)核价',templet:"#secondProcessColnumTpl"}
				,{field: 'can_checkout_stock', title:'补损',templet:'#coverLossColnumTpl'}
				,{field: 'available_checkout_count', title:'正品盈亏',templet:"#checkinoutColnumTpl"}
				,{field: 'mes_checkin_diff_pre', title:'订单状态',templet:function(d){return clientStatus[d.client_status]; }}
				,{field: 'cost_audit_time', title:'审核时间'}
			]]
			,done:function(res) {
				$("#TotalPer").html('正品率：<strong>'+res.avaribleTotalPer+'%</strong>， 次品率：<strong>'+res.defectiveTotalPer+'%</strong>， 报废率：<strong>'+res.allSscrapPre+'%</strong>')
				
			}
			
		});
		
		$(document).on('click','.process_btn',function(){
			var orderId = $(this).attr('data-id'),title=$(this).attr('title'),
			datatpl=$(this).attr("data-tpl");
			var orderNum=$(this).attr('data-ordernum');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var d = eval("(" + json+ ")");
			if(datatpl=='fabricTpl'){
				d=[];
				d['omlist'] = eval("(" + json+ ")");
				console.log(d['omlist'])
			}
			d['url'] = url;
			d['order_id'] = orderId;
			$(".size_name_span").html("__");
			$(".size_name_input").val('');
			$(".scan_code").hide();

			var content = laytpl($('#'+datatpl).html()).render(d);
			layerStockOutIn = layer.open({
				type: 1
				,area: ['760px','250px']
				,offset: '100px'
                ,shadeClose:1
                //,shade:[0.8, '#393D49']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:title+'，订单号：'+orderNum
				,content: content
			});
		});

		 //自定页
        window.searchdate = function(date) {
           	$("input[name=over_date_range]").val(date);
			var url='{:url()}?status='+status;
			$("#hisi-table-search").attr('action',url)
			$("#seacher").click();
           
            form.render();
		}


		// 尾部完成
		var layerDone = null;
		$(document).on('click','.tail-done',function(){
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			var content = laytpl($('#doneTpl').html()).render(d);
			layerDone = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'后整数录入'
				,content: content
			});
		});

	});
</script>